<%-- 
    Document   : XemDanhSachSanPhamSubpage
    Created on : May 22, 2011, 7:21:51 PM
    Author     : ToanNhan
--%>

<%@page import="Pojos.DanhMucSanPham"%>
<%@page import="Pojos.SanPham"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript" src="js/DangKyThanhVien.js" ></script>
<script type="text/javascript" src="js/XemDanhSachSanPham.js"></script>
<script src="js/jquery.tooltip.js" type="text/javascript"></script>

<center>
    <form action="QuanLySanPham.jsp" method="post" name="submitForm">
        <input type="hidden" id="action" name="action" value=""/>   
        <div class="box" style="clear:both; width:100%; text-align: center; margin: 5px 0px 5px 0px;">
            <div style="width: 100%;">
                <table width="100%" border="1px">                    
                    <%
                                List<SanPham> lstSanPham = (List<SanPham>) request.getAttribute("danhSachSanPham");
                                int count = 0;
                                for (SanPham sp : lstSanPham) {
                                    if (count % 4 == 0){                                        
                    %>
                    <tr>
                        <%} count ++;%>
                        <td valign="middle" align="center" width="25%">
                            <a id="sanPham" href="XemChiTietSanPham.jsp?maSanPham=<%=sp.getMaSanPham()%>">
                                <img width="100px" height="100px" src="/WebsiteBanHang<%=sp.getHinhSanPham()%>" alt="<%=sp.getMaSanPham()%>"/>
                            </a>
                            <br />
                            <%=sp.getTenSanPham()%>
                            <font color="red"><strong><%=sp.getGiaBan()%> VNĐ</strong></font>
                        </td>
                    <%
                        if (count % 4 == 0){
                            %>
                    </tr>
                    <%
                                }}
                                    if (count % 4 != 0){
                                        out.print("</tr>");
                                        }
                                request.setAttribute("danhSachSanPham", null);
                    %>
                </table>
            </div>
            <div style="width: 100%; text-align: center; margin-top: 5px;">
                <center>
                <table>
                    <tr>
                        <td align="center">
                            Hiển thị:   <select name="soLuongTrenTrang" id="soLuongTrenTrang">
                                <%  int soLuongTrenTrang = 20;
                                            if (request.getParameter("soLuongTrenTrang") != null) {
                                                soLuongTrenTrang = Integer.valueOf(request.getParameter("soLuongTrenTrang"));
                                            }
                                %>
                                <option <%if (soLuongTrenTrang == 5) {
                                                out.print("selected=\"true\"");
                                            }%> value="5">5</option>
                                <option <%if (soLuongTrenTrang == 10) {
                                                out.print("selected=\"true\"");
                                            }%> value="10">10</option>
                                <option <%if (soLuongTrenTrang == 15) {
                                                out.print("selected=\"true\"");
                                            }%> value="15">15</option>
                                <option <%if (soLuongTrenTrang == 20) {
                                                out.print("selected=\"true\"");
                                            }%> value="20">20</option>
                                <option <%if (soLuongTrenTrang == 25) {
                                                out.print("selected=\"true\"");
                                            }%> value="25">25</option>
                                <option <%if (soLuongTrenTrang == 30) {
                                                out.print("selected=\"true\"");
                                            }%> value="30">30</option>
                                <option <%if (soLuongTrenTrang == 50) {
                                                out.print("selected=\"true\"");
                                            }%> value="50">50</option>
                                <option <%if (soLuongTrenTrang == 100) {
                                                out.print("selected=\"true\"");
                                            }%> value="100">100</option>
                                <option <%if (soLuongTrenTrang == -1) {
                                                out.print("selected=\"true\"");
                                            }%> value="-1">All</option>
                            </select></td>
                            <%
                                        int trangHienTai = 1;
                                        if (request.getParameter("trangHienTai") != null) {
                                            trangHienTai = Integer.valueOf(request.getParameter("trangHienTai"));
                                        }
                                        int tongSoTrang = 1;
                                        if (request.getAttribute("tongSoTrang") != null) {
                                            tongSoTrang = (Integer)request.getAttribute("tongSoTrang");
                                        }
                                        if (trangHienTai == 1) {
                            %>
                            <td>
                                <img src="/WebsiteBanHang/images/GoFirst.png" align="middle" alt="First" height="32" width="64"/>
                            </td>
                            <td>
                                <img src="/WebsiteBanHang/images/GoPrevious.png" align="middle" alt="First" height="32" width="64"/>
                            </td>
                            <%                                    } else {
                            %>
                            <td>
                                <a href="/WebsiteBanHang/XemDanhSachSanPham.jsp?trangHienTai=1&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoFirst.png" align="middle" alt="First" height="32" width="64"/>
                                </a>
                            </td>
                            <td>
                                <a href="/WebsiteBanHang/XemDanhSachSanPham.jsp?trangHienTai=<%out.print((trangHienTai - 1));%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoPrevious.png" align="middle" alt="First" height="32" width="64"/>
                                </a>
                            </td>

                            <%
                                        }
                            %><td bgcolor="bisque"><%

                                        for (int i = 1; i <= tongSoTrang; i++) {
                                            out.print("&nbsp;");
                                            if (i != trangHienTai) {
                            %>
                                                <a href="/WebsiteBanHang/XemDanhSachSanPham.jsp?trangHienTai=<%=i%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                                    <%=i%>
                                                </a>
                        <%                                }
                                            else{
                                                out.print(i);
                                            }
                                    }
                                    out.print("&nbsp;");
                        %>
                            </td>
                            <%
                            if (trangHienTai == tongSoTrang) {
                            %>
                            <td>
                                <img src="/WebsiteBanHang/images/GoNext.png" align="middle" alt="Next" height="32" width="64"/>
                            </td>
                            <td>
                                <img src="/WebsiteBanHang/images/GoLast.png" align="middle" alt="Last" height="32" width="64"/>
                            </td>
                            <%                                    } else {
                            %>
                            <td>
                                <a href="/WebsiteBanHang/XemDanhSachSanPham.jsp?trangHienTai=<%=(trangHienTai + 1)%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoNext.png" align="middle" alt="Next" height="32" width="64"/>
                                </a>
                            </td>
                            <td>
                                <a href="/WebsiteBanHang/XemDanhSachSanPham.jsp?trangHienTai=<%=tongSoTrang%>&tongSoTrang=<%=tongSoTrang%>&soLuongTrenTrang=<%=soLuongTrenTrang%>">
                                    <img src="/WebsiteBanHang/images/GoLast.png" align="middle" alt="Last" height="32" width="64"/>
                                </a>
                            </td>
                            <%}%>
                    </tr>
                </table></center>
            </div>
        </div>
    </form>
</center>